home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
(A)G
/
(A)G6.ADF
/
docs
< prev
next >
Wrap
Text File
|
1988-05-25
|
53KB
|
1,849 lines
BATTLE DROIDS INSTRUCTIONS MANUAL
By Gregg Jacobs
Contents:
1 : Introduction
2 : Running the Arena
3 : Droid Hardware
4 : Programming Droids
5 : The Compiler
6 : The Battle Droids Arena
7 : Droid Instructions Summary
8 : Example Droid Program, Arthur
1 : Introduction
Battle droids is a game of artificial intelligence and
survival. Your job is to design, build, and program a droid
which is intelligent and deadly enough to survive in an arena
filled with enemy droids which were made by other people whose
job is the same as yours.
Your droid will be sent to the Battle Droids Arena where it
must fight, or die. Opposing droids have been programmed by
other people to find droids and destroy them. Thus, you must
make a better droid, one that will find the enemy droid before it
finds yours.
To build your droid, you must first buy a cpu for it. The
cpu is the brain of the droid; it will execute the instructions
in the program you later write for the droid. There exists
several different cpu's that run at different speeds. If you
want your droid to be able to move about the arena, you may buy a
drive for it; there are several different types that move at
different speeds. To be able to destroy the (hopefully) inferior
droids in the arena, you will need to buy a few weapons and some
ammunition for the weapons. There are expensive weapons that can
devastate another droid in a few good shots, there are weapons
with shots that move at higher speeds so that it is easier to get
a good shot in. You may also buy armor to protect your drive and
weapons. This is always a good idea, since the other droids in
the arena will not simply short circuit themselves out of fear.
They are in the arena with the same purpose as you: TO DESTROY
ALL OTHER DROIDS.
All of this hardware is of no practical use however, unless
you have something to run it. This is the program's job. Once
you have decided on what hardware you want your droid constructed
out of, you must tell the droid what to do with it. The program
gives the droid a set of instructions to follow once it is the
arena. The program tells the droid where to scan with its radar
to find other droids, where to fire once it has found them, and
what to do if it gets hit. The droid and its program are made
entirely before the droid is put into the arena. Once in the
arena, all the droid can do is let the cpu execute the program,
for better or worse.
To make your droid, simply type the definition for the cpu,
drive, weapons, armor, and program into a file. Any editor will
work as long as it writes to the file in ASCII (that is, plain
normal text). Once the hardware is defined in the file, and the
program is written in, the file is compiled. The compiler reads
the file you just made, and interpretates it so that your droid
may now be put in the arena.
How well your droid does relative to other droids is measured
by its score. There are two scores kept for each droid in the
arena. The first is the score for the current battle. The
second score is the droid's running average score. The running
average score includes the score for the current battle, so both
scores increase as your droid does damage, however the average
score increases more slowly because it is averages with previous
scores.
The current score is based on two things: how much damage
your droid causes, and its cost. Points are awarded as follows:
for each point of damage your droid causes, it gets a point, for
each droid that is destroyed while your droid is still running in
the arena, your droid gets 30 extra points. The number of points
obtained by your droid is divided by the square of its cost.
This requires a droid to be extremely viscious, yet inexpensive.
The idea is to get as much bang for the buck as possible. The
actual equation for calculating score is:
16000000.*points/(cost*cost)
The number 16000000. is included to make the score a reasonable
number from 0. to 1000. As you can see, a more expensive droid
will have a lower score than a less expensive droid if they both
obtained the same number of points. Every time the droid is
compiled, the value for its average score is set to 0.
Thus, destroy as many enemy droids as possible, and do it
with as little money as possible. Anyone can buy the best
weapons, all the ammunition they need, and as much armor as could
be imagined. No one is impressed by a $10000 droid destroying a
$2000 droid; one would hope it would be able to. Great droids
need something more. They need a program; they need
intelligence. Remember, "The sharpest blade is not always
enough." (Highlander)
2 : Running the Arena
To begin running a few battles right away between several
droids, go to CLI on the Amiga, and type:
bat n d1 d2 d3 ...
Where n is the number of battles to run. n may be from 1 to
99. d1 d2 d3 ... is the list of the names of the droids you want
to put in the arena. You may place up to eight in, but you must
put in at least two.
The battles will be run consecutively until finished. When
all battles are done running, click on the Q icon on the upper
right side of the status panel to quit.
The Battle Droid Arena may also be started by typing from
CLI:
battle
This will bring up a window showing the available droids in
the left column under the heading "AVAILABLE". You may scroll
through the list of available droids by clicking on the up and
down arrows between the AVAILABLE and SELECTED columns. To pick
one to put in the arena, click on its name. This will put its
name in the list under the heading "SELECTED". If you change
your mind, and don't want to run the droid, click on its name
under the SELECTED column, and it will be removed. The number of
battles to run may be adjusted by using the up and down arrows
next to the display showing the NUMBER OF BATTLES TO RUN. Once
you have selected all the droids you wish to run, and have
selected the number of battles, click on RUN. If you've changed
your mind, click on the window's close gadget.
3 : Droid Hardware
This section describes all the hardware available to your
droid, its function, and most importantly its cost.
CPU'S
Every droid needs a cpu. This component is required. The cpu
is the brain of a droid. The more expensive cpu's can execute
instructions in the program faster. The cpu's available are
shown below with their cost and relative execution speed.
Execution speed will be discussed further in the section of
Instructions Summary.
cpu type cost relative speed measured in
operations every
1/10 of a second
8bit $100 9
16bit $200 14
32bit $400 18
2x16bit $600 22
2x32bit $1000 25
To define the cpu for your droid, typethe following line into
your droid file:
cpu 2x16bit
This will give your droid a 2x16bit cpu which will add $600
to the total cost of your droid.
DRIVES
While the drive is not a required component of a droid as is
the cpu, it is highly recommended. Once your droid is located,
it will be an easy task to destroy it if it does not move to a
new location. The drive units, speeds, accelerations, costs, and
basic armor are shown below. The basic armor is how much armor
comes with the drive for free. This is just a measure of how
tough the drive naturally is. Additional armor may be added at a
cost of $7 for each unit.
drive cost basic armor top speed acceleration
type (meters/sec) (meters/sec/sec)
none $0 0 0. 0
budget $200 10 5. 1.0
track $500 60 10. 2.0
wheel $500 30 14. 1.5
hover $500 15 18. 1.0
turbohover $700 5 20. 1.5
To define a drive, put the following line in your droid file:
drive track 20
This gives you a track type drive with 20 armor units (in
addition to its basic 60 units).
The "none" type drive exists so that you can simply add armor
to your droid. The "budget" drive is a simple small flimsy car
type chassis, kind of like a Hyudail. The "track" is a pair of
tank treads (very tough) from surplus army Sherman tanks, "wheel"
is a three wheel solid rubber tire drive, "hover" is a hovercraft
(fairly flimsy and easily stopped), "turbohover" is a more
powerful and lighter version of the basic hover.
REGISTERS
When writing a program for a droid, you may find it useful to
have your program save numbers for later use. Your droid will
need some memory to store these numbers in. This memory is
created in the form of storage registers. Each register costs $2
for the extra memory. To define some storage registers in your
program, type:
reg 23
This will give you 23 storage registers to store numbers in.
The registers are numbered 0 to 22.
WEAPONS
If you plan on destroying other droids and getting points,
you will probably want to buy a weapon or two. You may have up
to four weapons (numbered 0 to 3) on your droid. To get a weapon,
you need to specify the type, how much armor you want protecting
it, and how much ammunition you want to have for it to fire.
Below are the available weapons, their cost, the speed of their
shots, the cost for ammunition, how long it takes for the weapon
to reload (so that it may fire again), and how much damage the
shot does on average.
weapon cost shot speed ammo cost reload time average
type (meters/sec) (per shot) (seconds) damage
lgun $150 100 $1 .6 7
mgun $225 80 $2 .8 12
hgun $300 60 $3 1.0 17
arail $100 70 $5 .8 15
brail $150 60 $8 1.0 20
crail $200 50 $10 1.2 25
laser $400 instant $5 1.0 15
proton $800 instant $10 2.0 30
To define a weapon type the following line into your droid
file:
weapon laser 10 50
This will give you a laser with 10 armor, and 50 shots. As
always the cost of armor is $7 for each point. So the total cost
of this weapon is $720 ($400 for the laser, $70 for armor, and
$250 for ammo).
The lgun is light caliber gun, the mgun a medium caliber, and
the hgun a heavy caliber. The guns fire explosive shells which
can be set to explode after traveling a specified distance. The
shrapnel from this explosion can cause damage to droids. The
damage will be less than a direct hit, but is better than
nothing. An arail is a rocket lauching rail that is made for
small rockets, brails are for medium rockets, and crails are for
heavy rockets. Each rocket is like the shells in that it may be
set to explode at a certain distance. The warheads carried on
the rockets are much larger than those on shells, however rockets
take much longer to arrive at their targets because they travel
slower. The ammunition for the rocket rails also costs more than
the gun ammo. The laser is a chemically activated laser; each
shot uses up a cartidge of chemicals. The proton is a particle
beam left over from SDI.
Note: The only piece of hardware that you are required to
buy is a cpu. You don't have to buy anything else, but the other
things really are very useful. A fast moving drive allows you to
dodge shots more easily if you keep moving; of course shooting
is much more difficult if you are moving. When you find another
droid while you are moving, you will need to correct for the fact
that you have moved from the time you found the droid to the time
you actually fire. The type of weapon can also help in hitting.
If you are firing at a moving droid, you will probably hit with a
laser or proton because the shot reaches the target
instantaneously. However, if you fire at a moving droid with a C
type rocket, the rocket will probably miss because the target
will have moved by the time the rocket arrives. In addition, if
a laser or proton miss, they will hit the wall, most probably not
hurting anything. If a rocket or shell misses, if your droid
took the time to tell the shell to explode at the distance to the
other droid, it may still cause damage. Of course lasers and
protons are very expensive, and will decrease your score by
costing more than other weapons.
Also, be careful to buy enough ammunition to keep your droid
going for the entire battle. Droids are reloaded between
battles, but it is very embarrassing to have your droid destroyed
because your droid thought it was blasting away at something, but
was actually out of ammo.
4 : Programming droids
To create a droid program, type the definitions for the cpu,
drive, weapons, registers, and the instructions for it to execute
into your droid file. You can use any editor to do this as long
as the editor writes its output to the file in ASCII (that is,
normal readable characters). The ED text editor is good for this
on the Amiga. This droid must then be compiled. For example, if
you write your droid to a file called "fred", type:
comp fred
This will compile fred, and create aversion called "fred.drd"
that the arena uses. More on the compiler later.
To program a droid you must understand the language the
droids use. Droids are programmed in Reverse Polish Notation
(RPN). This language is very efficient in terms of execution
speed, but must be understood to be used. Normal notation used
in most programming languages is arithemetic notation. In
arithmetic notation, you may write an equation as:
(5+3)
-----
(3+1)
The answer is 2. In RPN, the same equation is written as:
# 5, # 3, +, # 3, # 1, +, /
To understand this, let's look at how the cpu executes these
instructions. A register is a place where a number may be
stored. The cpu is made up of three registers that numbers are
stored in; they are called the x, y, and z registers.
Collectively they are called the "stack". This is because they
can be visualized as being stacked on top of each other:
z register
y register The Stack
x register
Some terms commonly used with the stack are "push" and
"drop". When the stack is "pushed", the value in the z register
is lost, the value in the y register is put into z, and the value
in the x register is put into y. This is visualized as the stack
being pushed up, with z falling off the top:
z lost /------- z
y --------/ /----- y Pushing the stack
x ----------/ /- x
new value--/
"Dropping" the stack means performing some operation on x
and y (such as adding them), and putting the result in the x
register, the z value is then put into the y register. This
can be visualized as the stack dropping down (note, the z value
is unchanged):
z ------\---------- z
y -\ \--------- y Dropping the stack
x --- operation---- x
Now, back to the example: (5+3)/(3+1). This is what happens
to the stack as the RPN instructions ( # 5, # 3, +, # 3, # 1, +,
/) are executed. Assume x, y, and z start with the value of 0 in
each:
z = 0 The first instruction, "# 5", pushes the z = 0
y = 0 stack up, and puts 5 in the x register. y = 0
x = 0 the resulting stack is shown on the right: x = 5
The next instruction, "# 3", again pushes the stack z = 0
and puts the number 3 in the x register: y = 5
x = 3
"+" is a stack dropping instruction. That is, it z = 0
operates on x and y, puts the result in x, and y = 0
drops z into y. The result is shown: x = 8
"# 3" will push the stack again, and put the z = 0
value of 3 into x: y = 8
x = 3
"# 1" pushes the stack, and puts 1 in the x z = 8
register. Note how the 8 which was in y is first y = 3
put into z, and the 3 in x was put into y before x = 1
the 1 is put into x.
"+" again will drop the stack. It adds x and y, z = 8
puts the result in x, then drops the value in z y = 8
into the y register. Note the z value is unchanged. x = 4
"/" is another stack drop instruction. It divides z = 8
y by x, puts the result into the x register, and y = 8
drops z into y. x = 2
Now the answer, 2, is in the x register. Look again how this
worked. First, 5 and 3 are added. Second, 3 and 1 are added.
Last, the result of the first is divided by the result of the
second.
Some instructions affect only the x register. For example,
"sin" will take the sine of the value in the x register and put
the result back into the x register. These instructions leave y
and z unchanged. In the section on Instructions Summary the
exact effect of each instruction on the stack is given. The
concepts of pushing and dropping the stack are very important,
and should be well understood in order to become proficient at
programming RPN.
The first thing you probably will want your droid to do is to
find a target. To do this, it is easiest to use the radar that
comes with your droid. To use it, the radar needs a direction to
scan, and a beam width. The direction is measured counter
clockwise with 0 being straight right, and the beam width is
measured to either side of the scan direction. The radar gets
this information from the stack. The scan angle is taken to be
the number in the x register, and the beam width is taken to be
the number in the y register. The value in the x register will
be changed to the distance to the closest droid in the radar
beam. If there is no droid in the beam, a value of -1 is put in
the x register. For example to scan straight up (90 degrees)
with a beam width of 10 degrees, put the following instructions
in your program:
# 10, # 90, radar
The first instruction, "# 10", will push the stack up, and
put 10 in the x register. "# 90" will push the stack up, the 10
will go into to y register, and 90 will be put in x. "radar"
will then scan at 90 degrees (in the x register) with a beam
width of 10 degrees (in the y register). The value in the x
register will then be changed to either the distance to the
closest droid within the beam, or -1 if no droid was in the beam.
The following diagram for this example may help clear up any
misunderstadings:
90 degrees
| | |____
| | / \ This droid will
| | | other | be detected
| 10 | 10 \droid/
| | |
| | |
| | |
| | | beam width=10
| | | (in y register)
| | |
| | scan angle=90
| | (in x register)
__|__
180 degrees /scan-\ 0 degrees
----------------------- | ning | --------------------------
\droid/
Of course, you may want to look in more than one direction.
This is easily accomplished if you use a storage register to hold
the scan angle. For example, assume you have at least one
register available:
# 0, sto 0
label start
# 10, sto+ 0
# 5, rcl 0, radar
goto start
There are a few new instructions here that need explaining
first. "sto 0" will change the number in register 0 to the
number in x; it does not change the stack. "label start" is a
label. This marks a place in the program. The "goto start"
later on will cause execution to jump back to the instruction
following the label. Any six character name may follow a label
instruction. The "sto+ 0" adds the number in the x register to
the number in register 0, and puts the result in register 0.
"rcl 0" pushes the stack, and puts the number in register 0 into
the x register.
So what does this do? First, 0 is pushed onto the stack, and
then stored into register 0. The "label start" is ignored. "#
10" pushes 10 onto the stack, and stores 10 plus register 0 in
register 0. This increments register 0 by 10. "# 5" pushes the
stack, and puts 5 in x. "rcl 0" pushes the stack, and puts the
value in register 0 in the x register. "radar" then looks with a
5 degree beam width (in y register) in the direction of the x
register which was recalled from register 0. Next, the "goto
start" is executed. The next instruction to be executed will be
the one following "label start", i.e. "# 10". This will keep
adding 10 to register 0, and using it as a scan angle. Thus each
time through it looks 10 degrees further counter clockwise.
Now how do you make it fire? Here comes several more new
instructions, so get ready:
cpu 16bit \ Give it a cpu to think. \
weapon lgun 10 50 \ A light gun with 10 armor and 50 shots. \
reg 2 \ Two storage registers allocated. \
equate angle 0 \ Anywhere it sees "angle", replace with "0"\
# 0, sto angle \ Set angle to 0 degrees. \
label start
# 10, sto+ angle \ Increment angle by 10 degrees. \
# 5, rcl angle, radar \ Scan at angle, width 5 degrees. \
\ Remember, the radar returns the \
\ distance to the droid in the x \
\ register, or -1 if none is found. \
x>0? goto fire \ If x is greater than 0, goto fire. \
goto start \ Goto start, and keep looking. \
label fire
sto dist \ Distance to droid is still in x register. \
rcl angle, aim \ Aim in the proper direction. \
rcl dist \ Need distance to explode at in x. \
fire 0 \ Fire the light gun (distance is in x).\
goto start \ Keep looking. \
This is a complete droid, since it has a cpu. The weapon is
defined as a lgun with 10 armor and 50 shots. Two registers are
given to it to store numbers in. Two things are here that are
very helpful to programming. The first is the "equate angle 0".
This means that anywhere the word "angle" is seen, it will be
replaced by "0". Thus, "sto angle" will be the same as "sto 0".
This allows words to be used instead of numbers for the
registers, and helps you make programs that are much more
readable. Second are comments. Anything between a pair of "\"'s
is ignored. This allows you to put in comments to tell what is
going on. "x>0?" is a conditional test. If x is greater than 0,
the next instruction ("goto fire") will be executed, otherwise it
will be skipped. Since radar returns the distance to a droid, or
-1 if none is seen, execution will jump to "label fire" if a
droid is there, or will "goto start" if one isn't. "aim" takes
the number in the x register and turns the turret containing the
weapons to face that direction (0 degrees is straight right, and
posative is measured counter clockwise). "fire 0" will fire the
light gun. The number in the x register when "fire 0" is
executed will give the distance for the shot to explode at. If
you don't get a direct hit, you may still have the shot blow up
nearby and cause damage.
Movement can be done quite easily also. All your droid needs
to know is the direction it wants to go, and how fast. This is
done with "heading" and "speed". "heading" takes the value in
the x register, and faces the droid in that direction . Heading
is measured positive counterclockwise (0 is straight right, 90
up, 180 left, and 270 down). "speed" takes the value in the x
register, and starts the droid moving at that speed. For
example:
# 0, heading
# 2, speed
This will move the droid at a heading of 0 degrees (straight
right) at a speed of 2 meters/second.
There are many more instructions to affect the droid, and for
the droid to find information about its environment (such as
where it is in the arena, if it has been hit, etc.). See the
list of droid control and droid environment instructions under
the instruction summary section for more details.
5 : The Compiler
The compiler is used to transform the file which contains
your program into something that can easily be read and run by
the Battle Droids Arena. This section gives details of compiler
syntax and use.
An instruction consists of the instruction name plus any
parameters it requires. For example "sto" must be followed by a
register number. All names and parameters must be separated by a
separator character. The separator characters are the blank,
carriage return, backspace, tab, comma, and colon. All
instructions must also be separated by a separator character.
Thus the following are equivalent:
#:5 #:3 + #:3 #:1 + /
and
# 5
# 3
+
# 3, # 1, +, /
Comments are delimited by "\". Any characters between a pair
of "\"'s are ignored.
The definitions for cpu, drive, weapons, and registers may
appear anywhere in the program, but it is most convenient to put
them at the beginning.
To compile a droid, type from CLI on the Amiga:
comp [-f -n] d1 d2 d3...
The -f is optional. If used, the compiler will run faster,
and the output on the screen will go by faster. The -n option
will not print to the screen at all. Use only the -f or -n
options, not both. d2 d3... is a list of droid names. Whenever
a droid is compiled, its average score is reset to 0. Whenever
an instruction in a droid program is changed, the droid must be
recompiled.
When the compiler reaches an unknown instruction in your
program, it will pause, show you what it doesn't understand and
ask if it should continue. Type "n" to have it stop.
6 : The Battle Droids Arena
This section describes the arena window, the droid monitor
window, and damaging droids. The Battle Droids Arena is started
as described in the section Running The Arena. Below is a
diagram of the arena and the Status Panel.
_____________________________________________________________
| | ___ ___ ___ ___ |
| | |Q| |N| |P| |S| |
| | --- --- --- --- |
| |C name $cost |
| C |----------- |
| | current/average |
| | |
| |C name $cost |
| |------- |
| | current/average |
| | |
| | |
| | |
| | |
| | time: |
| | battles |
-------------------------------------------------------------
A: Status Panel. Contains the Control Icons, Time Remaining,
and the current status of all the droids in the arena.
B : Control Icons, clicking these has the following results:
Q: This will quit the current sequence of battles, and
and return to CLI.
P: Pauses current battle until clicked again.
N: End the current battle and go to the next one.
S: Toggle the sound on and off.
C : Droid icon, name and cost. Clicking on the droid icon will
open the droid monitor window for that droid.
D : Armor bar. This shows the relative amount of armor remaining
on a droid. As armor is destroyed on a droid, the bar
gradually shortens. When the bars disappears, there is no
armor remaining on the droid.
E : Score. The first number is the score obtained in the
current set of battles. The second is the average score
obtained by the droid in its lifetime. Score is calculated as
follows:
16000000.*(points obtained)/(cost*cost)
Points obtained is the total damage caused by the droid plus
30 points for each droid destroyed while it was still
operating. The cost is shown next to the name.
F : Time Remaining. When timer runs to 0, the battle is
considered over. No more points are awarded to any droids.
Droid Monitor Window
The droid monitor window may be opened by clicking one of the
droid icons in the status panel. The monitor window shows the
name of the droid it is monitoring, the numbers contained in the
stack of the droid, and the instructions the droid is executing.
This is a very useful device for debugging a droid, and even for
learning the essentials of using the stack and RPN.
There are two controls for the monitor window. If the STEP
icon is clicked, execution will stop. Each time the STEP icon is
clicked, the next instruction in the droids program is executed,
the list of instructions is pushed up, and the executed
instruction is shown on the bottom of the list. The resulting
stack is also displayed. If the STEP icon is held down,
instructions will be executed at a slow pace. Click the RUN icon
to resume execution of the program at normal speed.
The monitor window may be closed by clicking the close window
gadget, or by clicking the droid icon again. If a different
droid icon is clicked, the current monitor window is shut down,
and a new one is opened for the most recently selected droid.
Damaging Droids
Droids receive damage from three sources: running into walls,
running into other droids, and being shot by other droids.
Hitting walls is usually avoidable, running into other droids is
not always avoidable, and very little can stop another droid from
shooting at yours apart from destroying it first.
The amount of damage that is done depends on its source.
Damage from hitting walls and other droids depends on the speed
your droid is going when it hits. The faster your droid was
moving when it hit the wall, the more damage is done to it. The
damage caused by different types of weapons is given under the
section on Hardware.
When a droid takes damage, all the points are randomly
applied to the drive or one of the weapons, that is only one
thing will be hit. Each point of damage will destroy one point
of armor. Once all the armor on the drive or a weapon is gone,
the next hit on that particular thing will destroy it. Weapons
operate at full function until destroyed, but the drive will
gradually loose top speed as its original base armor is
destroyed. Once all weapons and the drive are destroyed, the
next hit will destroy the droid.
7 : Droid Instructions Summary
Here is a synopsis of all the droid instructions available.
Each instruction also shows its relative execution time. For
example, "+" takes 1 relative execution time for a cpu to run it.
An 8bit cpu may run 9 instructions every 1/10 of a second. This
means it may do 9 adds every 1/10 of a second, or 90 adds per
second. Some instructions take longer to execute. For example,
"sto n" has an execution time of 3, thus an 8bit cpu may execute
3 "sto n" instructions in the same time it takes to execute 9 "+"
instructions. The speed of a cpu also affects this. An 8bit cpu
may run 9 adds in the same time it takes a 32 bit cpu to run 18
adds. If you have a droid that does a lot of thinking, it's a
good idea to give it a good cpu so that it won't take all day to
think.
Some instructions take more memory to hold than others.
Thus, the cost of each instruction differs. The cost of
instructions is printed out next to each instruction in your
program as it is compiled.
Here is how the functions are presented:
function name : stack effect : execution time : description
The letters used for stack effect are:
N : Instruction has no effect on stack.
P : Instruction pushes the stack up, puts something new in x.
D : Instruction drops the stack down; the instruction
will put the result of some operation on the x and y
registers into the x register.
X : Instruction only changes x register of the stack;
it leaves y and z unchanged.
U : The effect on the stack is unique to specific instruction,
where it will be defined.
equate s1 s2 :N:0: All subsequent occurrences of string s1 in the
droid code will be replaced by string s2. Only the
first ten characters of s1 and s2 are used. Up to
100equates may be made. Even instruction may be
changed, for example:
equate define equate
will allow you to use the word "define" instead of
the word "equate" in all subsequent program
instructions.
----- Droid Hardware Definition Instructions -----
reg n :N:0: Allocates n storage registers for your droid to use.
The registers are numbered 0 to n-1.
drive name n :N:0: Gives your droid a drive so that it can move.
name is any valid drive type, and n is the amount
of armor above the basic amount of armor (costs $7
per point of extra armor).
cpu name :N:0: Give your droid a cpu to think of type name.
weapon name a s :N:0: Define a weapon. name is any valid weapon
type. a is the amount of armor the weapon will
have protecting it (costs $7 per point of armor).
s is the number of shots the weapon will (cost is
given in the section on Hardware).
----- Droid Mathematical Operations -----
+ :D:2: Add the y and x registers, put the result in x.
- :D:2: Subtract y minus x, put the result in x.
* :D:4: Multiply y by x, put the result in x.
/ :D:4: Divide y by x, put the result in x.
chs :X:1: Change sign of number in x.
y^x :D:8: Raise y to the x power, put the result in x.
lnx :X:8: Take the natural logarithm of x, put the result in x.
e^x :X:8: Raise base e to the x power, put the result in x.
sin :X:12: Take sine of x, put result in x. x should be in
degrees.
cos :X:12: Take cosine of x, put the result in x. x should be in
degrees.
tan :X:12: Take tangent of x, put the result in x. x should be in
degrees.
asin :X:14: Take the arcsine of x, put the result x. (result in
degrees)
acos :X:14: Take the arccosine of x, put result in x. (result in
degrees)
atan :X:14: Take the arctangent of x, put result in x. (result in
degrees) Returns a result between -90 degrees and +90
degrees.
atan2 :X:16: Take arctangent of y register divided by x
register. x may be 0. Put result (in degrees) in x
register, drop stack. Returns a result between -180
degrees and +180 degrees.
r-d :X:3: Convert radians to degrees, put result in x.
d-r :X:3: Convert degrees to radians, put result in x.
1/x :X:3: divide 1 by the x register, put the result in x.
sqrt :X:8: take the square root of x, put the result in x.
abs :X:2: take the absolute value of x, put the result in x.
int :X:2: Drop any fractional value from the number in x.
rnd :X:2: Round off the number in x.
----- Number Entry and Storage Instructions -----
pi :P:2: Put 3.141592654 in the x register.
ran :P:5: Put a random number between 0 and 1 in the x register.
# number :P:1: Put number in the x register.
sto n :N:1: Put x register into storage register n.
rcl n :P:1: Put storage register n into x register.
sto+ n :N:4: Add storage register n plus the x register, put
result in n.
sto- n :N:4: Subtract register n minus x, put result in n.
sto/ n :N:6: Divide register n by x, put result in n.
sto* n :N:6: Multiply register n by x, put result in n.
stoind n :N:2: Store indirect, store the x register in the
register named by register n. e.g.: if register 5
contains 10, then stoind 5 will store the x register
into register 10.
rclind n :P:2: Recall indirect, recall to the x register, the
register named by register n.
incr n :N:1: Increment register n by 1.
decr n :N:1: Decrement register n by 1.
----- Droid Stack Instructions -----
swap :U:2: Switch the values in the x and y registers.
rup :U:2: Roll the stack up. x goes to y, y to z, and z to x.
rdn :U:2: Roll the stack down. z goes to y, y to x, and x to z.
enter :U:2: x is copied to y, y to z, and z to oblivion.
clst :U:2: Clear Stack. Sets x, y, and z to 0.
----- Comparison Instructions -----
x=y? :N:2: if the x register equals the y register, perform the
next instruction, otherwise skip it.
x>=y? :N:2: if x is greater or equal to y, perform the next
instruction, otherwise skip it.
x<=y? :N:2: if x is less or equal to y, perform the next
instruction, otherwise skip it.
x<y? :N:2: if the x register is less than the y register, perform
the next instruction, otherwise skip it.
x>y? :N:2: if the x register is greater than the y register,
perform the next instruction, otherwise skip it.
x!=y? :N:2: if the x register does not equal the y register,
perform the next instruction, otherwise skip it.
x=0? :N:2: if the x register equals 0, perform the next
instruction, otherwise skip it.
x>=0? :N:2: if the x register is greater or equal to 0, perform
the next instruction, otherwise skip it.
x<=0? :N:2: if the x register is less or equal to 0, perform the
next instruction, otherwise skip it.
x>0? :N:2: if the x register is greater than 0, perform the next
instruction, otherwise skip it.
x<0? :N:2: if the x register is less than 0, perform the next
instruction, otherwise skip it.
----- Execution Control Instructions -----
goto name :N:1: Jump execution to the label name
gosub name :N:5: Jump execution to the label name. When a return
is encountered, execution will continue at the
instruction following the gosub. gosub's may be
nested up to 10 levels deep.
label name :N:0: Label for a goto or gosub. Only the first six
characters of a label name are used, the rest are
ignored. So the compiler will see fredscum and
fredscum2 as the same label.
return :N:5: Continue execution at the instruction following a
gosub. If no gosub was ever called, start at the
beginning of the code.
----- Droid Control Instructions -----
delay :N:1: Delay, lets the cpu sit idle for the number of cycles
specified in the x register. Note the instruction takes
one cycle itself to execute, so specifying a delay of 1
would actually delay 2 cpu cycles.
radar :X:20: This is the instructions to use to find other
droids. The instruction uses the number in the x register
as the direction to scan, and the number in the y register
as a beam width. The beam width is measured from the scan
angle to both sides. Thus if the beam width is five
degrees, any droid that is less than five degrees left or
right of the scan angle will be seen. The distance to this
droid will be placed into the x register. If more than one
other droid exists within the scan beam, the closest
distance is put in the x register. If no other droid
exists within the beam, a -1 is put in the x register.
radar0 :X:10: This instructions is a shortened version of the
radar instruction. It automatically assumes a beam width
of 0 degrees. It requires the scan angle to be in the x
register. It replaces the x register with the distance to
the closest droid in the scan direction, or -1 if there is
no droid in the scan direction. The advantage of this
instruction over radar is that it takes much less time to
execute, so your droid runs much faster. If your droid
executes the following:
#60 radar0
the distance to the other droid will be put in the x
register. The following diagram should help explain this:
90 degrees
| /
| /
| _/__
| /other\
| | |
| \droid/
| /
| / The other droid will be seen,
| / and its distance to the scanning
| / droid will be put into the x
| / register of the scanning droid.
| / (This will replace the scanning
| / originally in x).
_____ / An angle of about 60 degrees in
/scan-\ the x register.
| ning | ---------------------------- 0 degrees ----
\droid/
radarw :X:10: This is a different form of radar beam. Instead of
a cone, the beam is a rectangle. See the diagram below
for an example of this. In the x register is the scan
angle as with all radar instructions. In the y register
is the beam width measured in meters. Droids are 4 meters
across. So the diagram below is for a beam width of 4.
The instructions to execute this would be:
# 4, # 60, radarw
As with all radar instructions, the number in the x
register is replaced with the distance to the closest
droid in the beam, or -1 if there are no droids in the
beam.
90 degrees
| ---> / beam / <---
| / width /
| / _ /__
| / /other\
| / | |
| / \droid/
| / /
| / / The other droid will be seen,
| / / and its distance to the scanning
| / / droid will be put into the x
|/ / register of the scanning droid.
| /
/| / A width of 4 meters in the y register,
/_____ / and an angle of about 60 degrees in
/scan-\ / the x register.
| ning | ---------------------------- 0 degrees ----
\droid/
fire n :N:25: This attempts to fire weapon number n. If the
weapon is still operating (has not received damage
sufficient to destroy it), and has ammunition remaining,
and it has reloaded, it will fire. If firing a gun or
rocket from a rail, the x register is used to tell the
shot how far to go before exploding. Thus, even if you can
not get a direct hit on anotherdroid, you may be able to
cause some damage from a nearmiss. If the weapon is an
instantaneous weapon such as a laser, it will not explode
at a given distance. If it does not score a direct hit,
it will hit a wall. Before a weapon may fire again, it
must reload. The time required to reload varies between
weapons, and is listed under the hardware section.
heading :N:5: Use the number in the x register as the new
direction to go (in degrees).
speed :N:5: Use the number in the x register as the new speed.
aim :N:12: Use the number in the x register as the new direction
to point the turret. 0 degrees is straight right, posative
is measured counter closckwise.
xmit channel :N:7: Transmit. This can be used to communicate
between droids. There are five different channels
to transmit on. Thus channel is a number 0-4. This
transmits the number in the x register to all other
droids. All droids will receive this number on the
channel specified. If a droid knows what to do with
this number, it will do what its programming
requests it to do. If a droid does not understand
it, or never looks at it, it may do nothing.
recv n :P:7: Put the number that has latest been received on
channel n in the x register.
destruct :N:20: This is a desperation command. If you know you
are about to die, and want to take a few others with
you, you can self destruct.
concede :N:20: This is an easy way out. If you don't want anyone
else to get any more points by punching you, you may
concede. This removes your droid from the arena
immediately.
----- Droid Environment Instructions -----
posx :P:15: Put the x position (from 0 to 100 meters) in the x
register. x is measured starting from the left (0) to the
right. The right wall is at 100 meters.
posy :P:15: Put the y position (from 0 to 100 meters) in the x
register. y is measured starting from the bottom (0) to the
top. The top wall is at 100 meters.
time :P:2: Push the stack up, and put the current game time in
the x register. Game time starts at 0 when the battle
starts and is incremented every 1/10 second.
dsts :U:10: Drive status. Puts information about the drive in
the stack:
x: total armor remaining
y: current speed
z: current heading
wsts n :U:10: Weapon status. Puts information about weapon
number n in the
stack:
x: total armor remaining
y: ammo left
z: time of last firing
hit :P:5: If the droid has been hit since this command was last
called, return a 1 to the x register, if not, return a 0.
note well: If your droid messes up, like dividing by 0, or trying
to access a storage register that doesn't exist, it will lock up.
It will stop executing instructions, and just sit there, or keep
going where it was headed (inertia, see Newton). Just a friendly
warning.
8 : Example Droid Program, Arthur
drive hover 100 \ give it a hover drive with 100 extra armor \
cpu 32bit \ make it think well. \
reg 5 \ only need a few storage registers. \
weap laser 30 70 \ give it a laser with 30 armor and 100 shots \
weap hgun 30 70 \ and a lgun with 30 armor and 70 shots \
\ note since the laser was defined first, it \
\ is weapon 0, and the lgun is 1 \
equate width 0 \ everywhere "width" is seen, it is replaced \
\ with "0" \
equate angle 1
equate dist 6
equate run 4
lab start \ where to come back to when starting again \
# 0 speed \ make sure it's not going anywhere \
sto 7 \ speed command does not change x, so 0 \
\ is stored in register 7 \
# 50, posy, -, enter, # 50, posx, -, atan2, # 90, -, sto run
\ direction to go when running away. \
# 90
sto width \ reg 0 holds beam width \
sto angle \ reg 1 holds angle looking at \
lab scan
hit \ see if it gets hit while looking \
x!=0? \ if it does, move \
goto move
rcl width \ recall the beam width \
rcl angle \ recall the scan angle \
radar \ anyone out there? \
x>0? \ found something \
sto dist \ store distance \
x>0?
goto sam
rcl width
# 2 *
sto+ angle \ add it \
lab sam \ found something \
# 2
sto/ width \ half the beam width \
rcl width
sto- angle \ take new width from scan angle \
# .6
x<y? \ if width is less than .6, start firing. \
goto scan
# 2, rcl dist, /, atan \ shoot to the left a bit \
rcl angle, +, aim
lab fire
hit
x!=0?
goto move
rcl dist
fire 0 \ fire the laser \
fire 1 \ fire the gun \
# .8 \ beam width is put in x \
rcl angle \ rcl pushes stack up, so beam width is now in y,\
\ and recalled number is in x \
radar \ is it still there ? \
x<0? goto start \ find it again if arthur lost it \
sto dist \ save the distance in case the target moved \
goto fire \ otherwise keep firing \
lab move
# 20 \ run away!!! \
speed
rcl run
heading
# 20
sto+ run \ change direction to run each time \
# 50 delay \ a delay \
# 0 speed \ and stop \
goto start \ find something to shoot \